package com.ruoyi.cbs.contract.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cbs.contract.domain.ContractorEquipment;
import com.ruoyi.cbs.contract.service.IContractorEquipmentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 承包商器具Controller
 * 
 * @author ruoyi
 * @date 2025-11-21
 */
@RestController
@RequestMapping("/contractor/equipment")
public class ContractorEquipmentController extends BaseController
{
    @Autowired
    private IContractorEquipmentService contractorEquipmentService;

    /**
     * 查询承包商器具列表
     */
    @PreAuthorize("@ss.hasPermi('contract:equipment:list')")
    @GetMapping("/list")
    public TableDataInfo list(ContractorEquipment contractorEquipment)
    {
        startPage();
        List<ContractorEquipment> list = contractorEquipmentService.selectContractorEquipmentList(contractorEquipment);
        return getDataTable(list);
    }

    /**
     * 导出承包商器具列表
     */
    @PreAuthorize("@ss.hasPermi('contract:equipment:export')")
    @Log(title = "承包商器具", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ContractorEquipment contractorEquipment)
    {
        List<ContractorEquipment> list = contractorEquipmentService.selectContractorEquipmentList(contractorEquipment);
        ExcelUtil<ContractorEquipment> util = new ExcelUtil<ContractorEquipment>(ContractorEquipment.class);
        util.exportExcel(response, list, "承包商器具数据");
    }

    /**
     * 获取承包商器具详细信息
     */
    @PreAuthorize("@ss.hasPermi('contract:equipment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(contractorEquipmentService.selectContractorEquipmentById(id));
    }

    /**
     * 新增承包商器具
     */
    @PreAuthorize("@ss.hasPermi('contract:equipment:add')")
    @Log(title = "承包商器具", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContractorEquipment contractorEquipment)
    {
        contractorEquipment.setCreateBy(getUsername());
        return toAjax(contractorEquipmentService.insertContractorEquipment(contractorEquipment));
    }

    /**
     * 修改承包商器具
     */
    @PreAuthorize("@ss.hasPermi('contract:equipment:edit')")
    @Log(title = "承包商器具", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContractorEquipment contractorEquipment)
    {
        return toAjax(contractorEquipmentService.updateContractorEquipment(contractorEquipment));
    }

    /**
     * 删除承包商器具
     */
    @PreAuthorize("@ss.hasPermi('contract:equipment:remove')")
    @Log(title = "承包商器具", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(contractorEquipmentService.deleteContractorEquipmentByIds(ids));
    }
}
